package series;

import java.io.FileNotFoundException;
import java.io.IOException;

import Exception.PropertiesException;
import Service.SeriesService;
import singleton.SeriesPropertiesSingleton;

public class Serie {
	
	private String nomSerie;
	private int saison;
	private int episode;
	private String old_name;
	private String extension;
	
	
	
	public Serie() {
		super();
	}
	
	



	public Serie(String nomSerie, int saison, int episode, String old_name,
            String extension) {
        super();
        this.nomSerie = nomSerie;
        this.saison = saison;
        this.episode = episode;
        this.old_name = old_name;
        this.extension = extension;
    }





    public String getNomSerie() {
		return nomSerie;
	}
	public void setNomSerie(String nomSerie) {
		this.nomSerie = nomSerie;
	}
	public int getSaison() {
		return saison;
	}
	public void setSaison(int saison) {
		this.saison = saison;
	}
	public int getEpisode() {
		return episode;
	}
	public void setEpisode(int episode) {
		this.episode = episode;
	}
	
	public String getOld_name() {
        return old_name;
    }


    public void setOld_name(String old_name) {
        this.old_name = old_name;
    }


    public String getExtension() {
        return extension;
    }


    public void setExtension(String extension) {
        this.extension = extension;
    }


    public String toString(){
	    return nomSerie + " S"+ getFormatter(saison) + "E" + getFormatter(episode) + "." + getExtension(); 
	}


    public static Serie isInSerie(String serie) throws FileNotFoundException, IOException, PropertiesException {
        SeriesService seriesServices = new SeriesService();
        String nom = seriesServices.getNom(serie);
        int episode = seriesServices.getEpisode(serie);
        int saison = seriesServices.getSaison(serie);
        if(nom != null && episode > 0 && saison > 0){
            Serie toReturn = new Serie(nom, saison , episode,  serie , Serie.getExtension(serie));
            return toReturn;
        }
        return null;
    }
    
    private static String getExtension(String serie) {
        String ext = serie.substring(serie.lastIndexOf("."));
        ext = ext.substring(1, ext.length());
        return ext;
    }


    public String getFormatter(int str){
        if(str < 10){
            return "0"+String.valueOf(str);
        }else{
            return String.valueOf(str);
        }
    }

	
}
